# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=urllib3
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.23
pkgrel=1
pkgdesc="HTTP library with thread-safe connection pooling and file post support (mingw-w64)"
url='https://github.com/shazow/urllib3'
license=('MIT')
arch=('any')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python3-ndg-httpsclient"
             "${MINGW_PACKAGE_PREFIX}-python2-ndg-httpsclient"
             "${MINGW_PACKAGE_PREFIX}-python3-pyasn1"
             "${MINGW_PACKAGE_PREFIX}-python2-pyasn1"
             "${MINGW_PACKAGE_PREFIX}-python3-pyopenssl"
             "${MINGW_PACKAGE_PREFIX}-python2-pyopenssl"
             #"${MINGW_PACKAGE_PREFIX}-python3-pysocks"
             #"${MINGW_PACKAGE_PREFIX}-python2-pysocks"
             "${MINGW_PACKAGE_PREFIX}-python3-mock"
             "${MINGW_PACKAGE_PREFIX}-python2-mock")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python2-nose"
              "${MINGW_PACKAGE_PREFIX}-python3-nose"
              "${MINGW_PACKAGE_PREFIX}-python2-tornado"
              "${MINGW_PACKAGE_PREFIX}-python3-tornado"
              "${MINGW_PACKAGE_PREFIX}-python2-coverage"
              "${MINGW_PACKAGE_PREFIX}-python3-coverage"
              "${MINGW_PACKAGE_PREFIX}-python2-psutil"
              "${MINGW_PACKAGE_PREFIX}-python3-psutil")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/shazow/urllib3/archive/${pkgver}.tar.gz")
sha256sums=('287c359d802e942ea55ce80710bcd9d5c08554b2c9dc3f52a56c77ce9f72451e')

prepare() {
  cd ${srcdir}
  cp -r ${_realname}-${pkgver} python2-build-${CARCH}
  cp -r ${_realname}-${pkgver} python3-build-${CARCH}
}

build() {
  cd "${srcdir}"
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done 
}

package_python3-urllib3() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-python3-certifi"
           "${MINGW_PACKAGE_PREFIX}-python3-idna")
  cd ${srcdir}/python3-build-${CARCH}
  ${MINGW_PREFIX}/bin/python3 setup.py build
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}"

  install -D -m644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}"/share/licenses/python3-${_realname}/LICENSE.txt
}

package_python2-urllib3() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-python2-certifi"
           "${MINGW_PACKAGE_PREFIX}-python2-idna")
  cd ${srcdir}/python2-build-${CARCH}
  ${MINGW_PREFIX}/bin/python2 setup.py build
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}"

  install -D -m644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}"/share/licenses/python2-${_realname}/LICENSE.txt
}

package_mingw-w64-i686-python2-urllib3() {
  package_python2-urllib3
}

package_mingw-w64-i686-python3-urllib3() {
  package_python3-urllib3
}

package_mingw-w64-x86_64-python2-urllib3() {
  package_python2-urllib3
}

package_mingw-w64-x86_64-python3-urllib3() {
  package_python3-urllib3
}
